namespace Angle.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class name : DbMigration
    {
        public override void Up()
        {
            RenameTable(name: "dbo.Users", newName: "SmatUsers");
            CreateTable(
                "dbo.Roles",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        RoleName = c.String(),
                        Discrible = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.RoleSystemFunctions",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        AuthorityLevel = c.Int(nullable: false),
                        Role_ID = c.Guid(),
                        SystemFunction_ID = c.Guid(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Roles", t => t.Role_ID)
                .ForeignKey("dbo.SystemFunctions", t => t.SystemFunction_ID)
                .Index(t => t.Role_ID)
                .Index(t => t.SystemFunction_ID);
            
            CreateTable(
                "dbo.SystemFunctions",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        FunctionName = c.String(),
                        DisplayText = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.SmatUserRoles",
                c => new
                    {
                        SmatUser_ID = c.Guid(nullable: false),
                        Role_ID = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.SmatUser_ID, t.Role_ID })
                .ForeignKey("dbo.SmatUsers", t => t.SmatUser_ID, cascadeDelete: true)
                .ForeignKey("dbo.Roles", t => t.Role_ID, cascadeDelete: true)
                .Index(t => t.SmatUser_ID)
                .Index(t => t.Role_ID);
            
            AddColumn("dbo.SmatUsers", "Name_EnglishName", c => c.String());
            AddColumn("dbo.SmatUsers", "Name_ChineseName", c => c.String());
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.SmatUserRoles", "Role_ID", "dbo.Roles");
            DropForeignKey("dbo.SmatUserRoles", "SmatUser_ID", "dbo.SmatUsers");
            DropForeignKey("dbo.RoleSystemFunctions", "SystemFunction_ID", "dbo.SystemFunctions");
            DropForeignKey("dbo.RoleSystemFunctions", "Role_ID", "dbo.Roles");
            DropIndex("dbo.SmatUserRoles", new[] { "Role_ID" });
            DropIndex("dbo.SmatUserRoles", new[] { "SmatUser_ID" });
            DropIndex("dbo.RoleSystemFunctions", new[] { "SystemFunction_ID" });
            DropIndex("dbo.RoleSystemFunctions", new[] { "Role_ID" });
            DropColumn("dbo.SmatUsers", "Name_ChineseName");
            DropColumn("dbo.SmatUsers", "Name_EnglishName");
            DropTable("dbo.SmatUserRoles");
            DropTable("dbo.SystemFunctions");
            DropTable("dbo.RoleSystemFunctions");
            DropTable("dbo.Roles");
            RenameTable(name: "dbo.SmatUsers", newName: "Users");
        }
    }
}
